{# Copyright 2014-2016 Siemens AG

   Copying and distribution of this file, with or without modification,
   are permitted in any medium without royalty provided the copyright notice and this notice are preserved.
   This file is offered as-is, without any warranty.
#}
{% extends "include/base.html.twig" %}

{% block content %}

{% if error is empty %}
<form name="Updatefm" action="{{ actionUri }}" method="post">
  <input type="hidden" name="req_marydone" value="{{ req_marydone }}"/>
  <input type="hidden" name="req_shortname" value="{{ req_shortname }}"/>
  <input type="hidden" name="rf_pk" value="{{ rf_pk }}"/>
  <input type="hidden" name="{% if rf_pk %}updateit{% else %}addit{% endif %}" value="true"/>
  <table>
    {% import 'include/macros.html.twig' as macro %}
    <tr>
      <td align="right">{{ 'Active'|trans }}</td>
      <td align="left">{{ macro.select('rf_active',boolYesNoMap,'rf_active',rf_active) }}</td>
    </tr>
    <tr>
      <td align="right">{{ 'Checked'|trans }}</td>
      <td align="left">{{ macro.select('marydone',boolYesNoMap,'marydone',marydone) }}</td>
    </tr>
    <tr>
      <td align="right">{{ 'SPDX Compatible'|trans }}</td>
      <td align="left">{{ macro.select('rf_spdx_compatible',boolYesNoMap,'rf_spdx_compatible',rf_spdx_compatible) }}</td>
    </tr>
    <tr>
      <td align="right">{{ "Short name"|trans }}</td>
      {% if rfId %}
        <td><input type="text" name="rf_shortname" value="{{ rf_shortname|e }}" size="30" readonly> ({{ 'must be unique'|trans }})</td>
      {% else %}
        <td><input type="text" name="rf_shortname" value="{{ rf_shortname|e }}" size="30"> ({{ 'must be unique'|trans }})</td>
      {% endif %}
    </tr>
    <tr>
      <td align="right">{{ "Full name"|trans }}</td>
      <td><input type="text" name="rf_fullname" value="{{ rf_fullname|e }}" size="60"></td>
    </tr>
    <tr>
      <td align="right">{{ 'License Text'|trans }}{% if isReadOnly %} ({{ 'read only'|trans }}){% endif %}</td>
      <td><textarea name="rf_text" rows="10" cols="80" {% if isReadOnly %} readonly="readonly"{% endif %}>{{ rf_text|e }}</textarea></td>
    </tr>
    <tr>
      <td align="right">{{ 'Text Updatable'|trans }}</td>
      <td align="left">{{ macro.select('rf_text_updatable',boolYesNoMap,'rf_text_updatable',rf_text_updatable) }}</td>
    </tr>
    <tr>
      <td align="right">{{ 'Detector Type'|trans }}</td>
      <td align="left">{{ macro.select('rf_detector_type',detectorTypes,'rf_detector_type',rf_detector_type) }}</td>
    </tr>
    <tr>
      <td align=right>
        {{ 'URL'|trans }}
        {% if rf_url %}<a href="{{ rf_url }}"><img border="0" src="images/right-point-bullet.gif"/></a>{% endif %}
      </td>
      <td><input type="text" name="rf_url" value="{{ rf_url }}" size="60"></td>
    </tr>
    <tr>
      <td align="right">{{ 'Public notes'|trans }}</td>
      <td><textarea name="rf_notes" rows="5" cols="80">{{ rf_notes|e }}</textarea></td>
    </tr>
    <tr>
      <td align="right">{{ 'Conclusion'|trans }}</td>
      <td align="left">{{ macro.select('rf_parent',parentMap,'rf_parent',rf_parent, 'class="ui-render-select2"') }}</td>
    </tr>
    <tr>
      <td align="right">{{ 'Reported license'|trans }}</td>
      <td align="left">{{ macro.select('rf_report',reportMap,'rf_report',rf_report, 'class="ui-render-select2"') }}</td>
    </tr>
    <tr>
      <td align="right">{{ 'Risk level'|trans }}</td>
      <td align="left">{{ macro.selectsingle('risk_level',range(0,5),'risk_level',risk_level) }}</td>
    </tr>
    <tr>
      <td align="right">{{ "Associated Obligations"|trans }}</td>
      <td align="left">{{ macro.selectwitharray(obligationSelectorName, obligationTopics, obligationSelectorId, obligationSelected, 'style="min-width:575px;"', 8) }}</td>
    </tr>
  </table>
  {% if rfId %}
    <a href="?mod=admin_license_to_csv&amp;rf={{ rfId }}" class="buttonLink">{{ 'Export as CSV'|trans }}</a>
  {% endif %}
  <input type="submit" value="{% if rfId %}{{ 'Update'|trans }}{% else %}{{ 'Add license'|trans }}{% endif %}"/>
</form>
{% else %}
  {{ error }}
{% endif %}
{% endblock %}

{% block foot %}
  {{ parent() }}
  {% set riskSelectId = 'risk_level' %}
  <script type="text/javascript">{% include "riskLevel_select.js.twig" %}</script>
  <script type="text/javascript">
    $('#{{ obligationSelectorId }}').select2({'placeholder': 'Select obligations associated with this license'});
  </script>
{% endblock %}
